<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Crypt
 *
 * @author dejo
 */
class Tc_Crypt {
    private $salt = "je moeder op een houtvlot";

    public function encrypt($text, $encoding = false){
        $string = trim(base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $this->salt, $text, MCRYPT_MODE_ECB, mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND))));
        if($encoding === true) {
            $string = urlencode($string);
        }
        return $string;
    }

    public function decrypt($text, $encoding = false){
        if($encoding === true) {
            $text = urldecode($text);
        }
        return trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $this->salt, base64_decode($text), MCRYPT_MODE_ECB, mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND)));
    }
}
?>
